﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Shumisen.Core
{
	internal static class EnumerableExtensions
	{
		internal static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> source)
		{
			Guard.ArgumentNotNull(source, "source");
			var readOnlyCollection = source as ReadOnlyCollection<T>;
			if (readOnlyCollection != null)
			{
				return readOnlyCollection;
			}
			return new ReadOnlyCollection<T>(source.ToList());
		}
	}
}